import os
import json

# 3.46
trajectories_save_path = "hotpot/trajectories_test_gpt-4o-mini_simple_1iterations"

# 3.44
# trajectories_save_path = "hotpot/trajectories_test_gpt-4o_simple_1iterations"

# 3.477
# trajectories_save_path = "hotpot/trajectories_test_gpt-4-turbo_simple_1iterations"

# Average succeed length:  3.525
trajectories_save_path = 'hotpot/trajectories_bad-thought/trajectories_epoch2_test_gpt-4o-mini_beam_1iterations'

length_list = []

for file in os.listdir(trajectories_save_path):
    if not file.endswith('json'):
        continue
    with open(os.path.join(trajectories_save_path, file)) as f:
        result=json.load(f)
    if result['best child em'] == 1:
        depth=0
        node = result
        while node['children']:
            node = node['children'][0]
            depth += 1
        length_list.append(depth)
print("Average succeed length: ", sum(length_list)/len(length_list))
